package wiki.douzi.helpyougrow.service.impl;

import wiki.douzi.helpyougrow.domain.Foods;
import wiki.douzi.helpyougrow.mapper.FoodsMapper;
import wiki.douzi.helpyougrow.service.FoodsService;
import org.springframework.stereotype.Service;

import java.util.List;
import javax.annotation.Resource;

/**
 * (Foods)表服务实现类
 *
 * @author Douzi
 * @since 2022-06-18 16:39:25
 */
@Service("foodsService")
public class FoodsServiceImpl implements FoodsService {
    @Resource
    private FoodsMapper foodsMapper;

    /**
     * 查询所有数据
     *
     * @return 实例对象集合
     */
    @Override
    public List<Foods> queryAll() {
        return this.foodsMapper.queryAll();
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Foods queryById(Integer id) {
        return this.foodsMapper.queryById(id);
    }

    /**
     * 新增数据
     *
     * @param foods 实例对象
     * @return 实例对象
     */
    @Override
    public Foods insert(Foods foods) {
        this.foodsMapper.insert(foods);
        return foods;
    }

    /**
     * 修改数据
     *
     * @param foods 实例对象
     * @return 实例对象
     */
    @Override
    public Foods update(Foods foods) {
        this.foodsMapper.update(foods);
        return this.queryById(foods.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.foodsMapper.deleteById(id) > 0;
    }
}

